<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item  label-width="120" label="农产品名称" prop="agroProductName">
        <el-input v-model="queryParams.agroProductName" placeholder="请输入农产品名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label-width="120" label="农产品类别" prop="agroProductType">
        <el-select v-model="queryParams.agroProductType" placeholder="请选择农产品类别" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.AGRO_REVIEW_PRODUCT_TYPE)"
                       :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item  label-width="120" label="农产品产地" prop="agroProductOrigin">
        <el-input v-model="queryParams.agroProductOrigin" placeholder="请输入农产品产地" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label-width="120" label="环境监测负责人" prop="environmentMonitoringPerson">
        <el-input v-model="queryParams.environmentMonitoringPerson" placeholder="请输入环境监测负责人" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label-width="120" label="环境监测结果" prop="environmentMonitoringResult">
        <el-select v-model="queryParams.environmentMonitoringResult" placeholder="请选择环境监测结果（0.不合格 1.合格）" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.AGRO_REVIEW_ENVIRONMENT_MONITORING_RESULT)"
                       :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label-width="120" label="质量检测结果" prop="qualityTestResult">
        <el-select v-model="queryParams.qualityTestResult" placeholder="请选择质量检测结果（0.抽检不合格 1.抽检合格）" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.AGRO_REVIEW_QUALITY_TEST_RESULT)"
                       :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="送检日期" prop="qualityTestSamplingTime">
        <el-date-picker v-model="queryParams.qualityTestSamplingTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label-width="120" label="质量检测日期" prop="qualityTestTime">
        <el-date-picker v-model="queryParams.qualityTestTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['agro:review:create']">新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"-->
<!--                   v-hasPermi="['agro:review:export']">导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="溯源二维码" align="center">
        <template v-slot="scope">
          <image-preview v-if="scope.row.agroCodeImg" :src="scope.row.agroCodeImg" :width="'100px'"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="农产品名称" align="center" prop="agroProductName" />
      <el-table-column label="农产品类别" align="center" prop="agroProductType">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.AGRO_REVIEW_PRODUCT_TYPE" :value="scope.row.agroProductType" />
        </template>
      </el-table-column>
      <el-table-column label="农产品产地" align="center" prop="agroProductOrigin" />

      <el-table-column label="环境监测负责人" align="center" prop="environmentMonitoringPerson" />
      <el-table-column label="环境监测结果" align="center" prop="environmentMonitoringResult">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.AGRO_REVIEW_ENVIRONMENT_MONITORING_RESULT" :value="scope.row.environmentMonitoringResult" />
        </template>
      </el-table-column>
      <el-table-column label="生产视频监控地址" align="center" prop="produceVideoMonitorUrl" />
      <el-table-column label="生产视频监控时间" align="center" prop="produceVideoMonitorTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.produceVideoMonitorTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质量检测机构" align="center" prop="qualityTestOrganization" />
      <el-table-column label="质量检测结果" align="center" prop="qualityTestResult">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.AGRO_REVIEW_QUALITY_TEST_RESULT" :value="scope.row.qualityTestResult" />
        </template>
      </el-table-column>
      <el-table-column label="送检日期" align="center" prop="qualityTestSamplingTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.qualityTestSamplingTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质量检测日期" align="center" prop="qualityTestTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.qualityTestTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['agro:review:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['agro:review:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {deleteReview, exportReviewExcel, getReviewPage} from "@/api/agro/review";
import ImagePreview from "@/components/ImagePreview";

export default {
  name: "Review",
  components: {
    ImagePreview
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 溯源信息列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        pollingType: null,
        agroProductName: null,
        agroProductType: null,
        agroProductDescribe: null,
        agroProductOrigin: null,
        agroProductManufacturer: null,
        agroProductPrice: null,
        agroProductWeight: null,
        storageMethod: null,
        packagingMethod: null,
        storageTime: [],
        produceDate: [],
        environmentMonitoringType: null,
        environmentMonitoringMethod: null,
        environmentMonitoringPerson: null,
        environmentMonitoringResult: null,
        environmentMonitoringStartTime: [],
        environmentMonitoringEndTime: [],
        produceVideoMonitorUrl: null,
        produceVideoMonitorTime: [],
        qualityTestOrganization: null,
        qualityTestPerson: null,
        qualityTestMethod: null,
        qualityTestProjectBasis: null,
        qualityTestResult: null,
        qualityTestSamplingTime: [],
        qualityTestTime: [],
        createTime: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getReviewPage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        pollingType: undefined,
        agroProductName: undefined,
        agroProductType: undefined,
        agroProductDescribe: undefined,
        agroProductOrigin: undefined,
        agroProductManufacturer: undefined,
        agroProductPrice: undefined,
        agroProductWeight: undefined,
        storageMethod: undefined,
        packagingMethod: undefined,
        storageTime: undefined,
        produceDate: undefined,
        environmentMonitoringType: undefined,
        environmentMonitoringMethod: undefined,
        environmentMonitoringPerson: undefined,
        environmentMonitoringResult: undefined,
        environmentMonitoringStartTime: undefined,
        environmentMonitoringEndTime: undefined,
        produceVideoMonitorUrl: undefined,
        produceVideoMonitorTime: undefined,
        qualityTestOrganization: undefined,
        qualityTestPerson: undefined,
        qualityTestMethod: undefined,
        qualityTestProjectBasis: undefined,
        qualityTestResult: undefined,
        qualityTestSamplingTime: undefined,
        qualityTestTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/agro/review/edit",
        query: {type: "add",},
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.$router.push({
        path: "/agro/review/edit",
        query: {type: "edit",id:id},
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除溯源信息编号为"' + id + '"的数据项?').then(function() {
          return deleteReview(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有溯源信息数据项?').then(() => {
          this.exportLoading = true;
          return exportReviewExcel(params);
        }).then(response => {
          this.$download.excel(response, '溯源信息.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
